#!/bin/bash

cd $(dirname $(readlink -f $0))

SRC_ROOT=$WS_ROOT/moveit2

export CMAKE_COMMAND=$OHOS_SDK/native/build-tools/cmake/bin/cmake

cp colcon.meta ..
cp colcon_defaults.yaml ..
cp ohos.toolchain.docker.cmake ..

echo "NOTE: This built will skip moveit_ros_perception (Use OpenGL & GLEW for GUI) and wiimote/wiimote_msgs/spacenav (Use bluetooth library)."
read -p "Source Root: ${SRC_ROOT}; Dependency Root: ${SRC_ROOT}/moveit_deps; Press any key (except Ctrl+C) to continue... "

cd $SRC_ROOT

OHOS_CPU=x86_64
OHOS_ARCH=x86_64
ROS2_HOST_DIR=${WS_ROOT}/moveit2/install

colcon build --metas $SRC_ROOT/colcon.meta --merge-install --event-handlers console_cohesion+ --cmake-args \
	-DBUILD_TESTING=OFF \
	-DCMAKE_BUILD_TYPE=Release \
	-DCMAKE_VERBOSE_MAKEFILE=ON \
	-Wno-dev \
	-DCMAKE_TOOLCHAIN_FILE=$OHOS_SDK/native/build/cmake/ohos.toolchain.cmake \
	-DOHOS_ARCH=${OHOS_ARCH} \
	-DSSRVODKA_APPEND_C_PREPROCESSOR_FLAGS="-DSDL_DISABLE_IMMINTRIN_H" \
	-DSSRVODKA_APPEND_CMAKE_PREFIX_PATH="${ROS2_HOST_DIR};" \
	-DSSRVODKA_APPEND_COMMON_CFLAGS="-I${ROS2_HOST_DIR}/include " \
	-DPYTHON_INCLUDE_DIR=${OHOS_SDK}/native/sysroot/usr/include/python3.12 \
	-DPYTHON_LIBRARY=${OHOS_SDK}/native/sysroot/usr/lib/${OHOS_CPU}-linux-ohos/libpython3.12.so

